{% extends "home/home.html" %}

{% import "ui/home_comment_page.html" as pg %}

{% block css %}
    <!--播放页面-->

    <script type="text/javascript" src="{{ url_for('static',filename='ueditor/ueditor.config.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static',filename='ueditor/ueditor.all.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static',filename='ueditor/lang/zh-cn/zh-cn.js') }}"></script>

    <script>
        SyntaxHighlighter.all();
    </script>
    <!--播放页面-->
{% endblock %}
{% block content %}
    <div class="row">
        <div class="col-md-8">
            <div id="moviecontainer"></div>
        </div>
        <div class="col-md-4" style="height:500px;">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title"><span class="glyphicon glyphicon-facetime-video"></span>&nbsp;电影介绍</h3>
                </div>
                <div class="panel-body" style="height:459px; overflow: scroll">
                    <table class="table">
                        <tr>
                            <td style="width:30%;color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-film"></span>&nbsp;片名
                            </td>
                            <td>{{ movie.title }}</td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-tag"></span>&nbsp;标签
                            </td>
                            <td>{{ movie.tag.name }}</td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-time"></span>&nbsp;片长
                            </td>
                            <td>{{ movie.length }} min</td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-map-marker"></span>&nbsp;地区
                            </td>
                            <td>{{ movie.area }}</td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-star"></span>&nbsp;星级
                            </td>
                            <td>
                                <div>
                                    {% for num in range(1,movie.star + 1) %}
                                    <span class="glyphicon glyphicon-star" style="color:#FFD119"></span>

                                    {% endfor %}
                                    {% for num in range(1, 6 - movie.star) %}
                                    <span class="glyphicon glyphicon-star-empty" style="color:#FFD119"></span>
                                    {% endfor %}
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-calendar"></span>&nbsp;上映时间
                            </td>
                            <td>{{ movie.release_time }}</td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-play"></span>&nbsp;播放数量
                            </td>
                            <td>{{ movie.playnum }}</td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-comment"></span>&nbsp;评论数量
                            </td>
                            <td>{{ movie.commentnum }}</td>
                        </tr>
                        <tr>
                            <td style="color:#ccc;font-weight:bold;font-style:italic;">
                                <span class="glyphicon glyphicon-picture"></span>&nbsp;影片介绍
                            </td>
                            <td>
                            {{ movie.info }}
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-12" style="margin-top:6px;">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title"><span class="glyphicon glyphicon-comment"></span>&nbsp;电影评论</h3>
                </div>
                <div class="panel-body">
                    {% if "user" not in session %}
                    <div class="alert alert-danger alert-dismissible" role="alert">
                        <button type="button" class="close" data-dismiss="alert">
                            <span aria-hidden="true">×</span>
                            <span class="sr-only">Close</span>
                        </button>
                        <strong>请先<a href="{{ url_for('home.login') }}" target="_blank" class="text-info">登录</a>，才可参与评论！</strong>
                    </div>
                    {% endif %}
                    <ol class="breadcrumb" style="margin-top:6px;">
                        <li>全部评论({{ movie.commentnum }})</li>
                    </ol>

                    {% include "admin/layout/flash_message.html" %}

                    {% if "user" in session %}
                    <form role="form" style="margin-bottom:6px;" method="post">
                        <div class="form-group">
                            <div>
                                <label for="input_content">{{ form.content.label }}</label>
                                {{ form.content }}
                                {% include "admin/layout/content_error.html" %}
                            </div>
                            <div class="col-xs-12" id="error_content"></div>
                        </div>
                         {{ form.csrf_token }}
                         {{ form.submit }}
                        &nbsp;
                        {% if col_count == 1 %}
                        <a class="btn btn-success" id="btn-col">
                            <span class="glyphicon glyphicon-heart"></span>&nbsp;
                            <span id="col_content">取消收藏</span>
                        </a>
                        {% else %}
                        <a class="btn btn-danger" id="btn-col">
                            <span class="glyphicon glyphicon-heart"></span>&nbsp;
                            <span id="col_content">收藏电影</span>
                        </a>
                        {% endif %}
                    </form>
                    {% endif %}

                    <ul class="commentList">
                        {% for v in page_data.items %}
                        <li class="item cl">
                            <a>
                                <i class="avatar size-L radius">
                                    <img alt="50x50" width="50" height="50"
                                         src="{{ url_for('static',filename='uploads/user/'+v.user.avatar) }}" class="img-circle"
                                         style="border:1px solid #abcdef;">
                                </i>
                            </a>
                            <div class="comment-main">
                                <header class="comment-header">
                                    <div class="comment-meta">
                                        <a class="comment-author" href="user.html">{{ v.user.name }}</a>
                                        评论于
                                        <time title="{{ v.addtime }} " datetime="{{ v.addtime }} ">
                                            {{ v.addtime }}
                                        </time>
                                    </div>
                                </header>
                                <div class="comment-body">
                                    {{ v.content | safe}}
                                </div>
                            </div>
                        </li>
                        {% endfor %}
                    </ul>
                    <div class="col-md-12 text-center">
                        <nav aria-label="Page navigation">
                            {% if page_data.items %}
                            {{ pg.page(page_data,'home.video',movie.id) }}
                            {% endif %}
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
        var ue = UE.getEditor('input_content',{
            toolbars: [
                ['fullscreen', 'emotion', 'preview', 'link']
            ],
            initialFrameWidth:"100%",
            initialFrameHeight:"100",
        });

        // 点击收藏电影
        $(function () {
            $("#btn-col").click(function(){
                var mid = {{ movie.id }}
                var uid = {{ session['user_id'] }}
                $.ajax({
                    url:"{{ url_for('home.collections_add') }}",
                    type:"POST",
                    data:{
                        "mid":mid,
                        "uid":uid
                    },
                    dataType:"json",
                    success:function(res){
                        if(res.code == 1){
                            // alert('收藏成功')
                            $("#col_content").text("取消收藏")
                            $("#col_content").parent().removeClass("btn-danger").addClass("btn-success")
                        }else{
                            // alert('取消收藏成功')
                            $("#col_content").text("收藏电影")
                            $("#col_content").parent().addClass("btn-danger")
                        }
                    }
                })
            })
        })
    </script>
{% endblock %}